package com.cpi.cornpp.monthsperiods.converter;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.cpi.cornpp.monthsperiods.dto.MonthsPeriodsDTO;
import com.cpi.cornpp.monthsperiods.view.MonthsPeriodsForVersionDTO;
import com.cpi.cornpp.monthsperiods.view.MonthsPeriodsView;
import com.cs.common.utils.StringUtils;


/**
 * Months Periods Converter
 * @author Edgar Joao
 *
 */
public class MonthsPeriodsConverter {
	
	public List convertVersionDTOsToViews(List monthsPeriodsForVersionDTOs){
		List monthsPeriodsViews = null;
		monthsPeriodsViews = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(monthsPeriodsForVersionDTOs)){
			Iterator iterator = monthsPeriodsForVersionDTOs.iterator();
			MonthsPeriodsForVersionDTO monthsPeriodsForVersionDTO = null;
			while(iterator.hasNext()){
				monthsPeriodsForVersionDTO = (MonthsPeriodsForVersionDTO) iterator.next();
				monthsPeriodsViews.add(convertVersionDTOToView(monthsPeriodsForVersionDTO));
			}
		}
		return monthsPeriodsViews;
	}
	
	public MonthsPeriodsView convertVersionDTOToView(MonthsPeriodsForVersionDTO monthsPeriodsForVersionDTO){
		MonthsPeriodsView monthsPeriodsView = null;
		
		monthsPeriodsView = new MonthsPeriodsView();
		monthsPeriodsView.setMonthPeriodId(monthsPeriodsForVersionDTO.getMonthPeriodVersionId().intValue());
		monthsPeriodsView.setShortName(monthsPeriodsForVersionDTO.getShortName());
		monthsPeriodsView.setDescription(monthsPeriodsForVersionDTO.getDescription());
		monthsPeriodsView.setMonth(monthsPeriodsForVersionDTO.getMonth());
		monthsPeriodsView.setYear(monthsPeriodsForVersionDTO.getYear());
		monthsPeriodsView.setListDescription(monthsPeriodsForVersionDTO.getListDescription());
		monthsPeriodsView.setLabel(new StringBuffer(monthsPeriodsForVersionDTO.getShortName()).append(StringUtils.SPACE_CHAR).append(monthsPeriodsForVersionDTO.getYear()).toString());
		
		return monthsPeriodsView;
	}

	/**
	 * Months Periods Converter View to DTO
	 * @param view
	 * @return
	 */
	public MonthsPeriodsDTO converterMonthsPeriodsViewToDTO(MonthsPeriodsView view){
		MonthsPeriodsDTO monthsPeriodsDTO = null;
		monthsPeriodsDTO = new MonthsPeriodsDTO();
		monthsPeriodsDTO.setMonthPeriodId(view.getMonthPeriodId());
		monthsPeriodsDTO.setShortName(view.getShortName());
		monthsPeriodsDTO.setDescription(view.getDescription());
		monthsPeriodsDTO.setMonth(view.getMonth());
		monthsPeriodsDTO.setYear(view.getYear());
		monthsPeriodsDTO.setListDescription(view.getListDescription());
		return monthsPeriodsDTO;		
	}
	
	
	/**
	 * Months Periods Converter DTO to View
	 * @param view
	 * @return
	 */
	public MonthsPeriodsView converterMonthsPeriodsDtoToView(MonthsPeriodsDTO dto){
		MonthsPeriodsView monthsPeriodsView = null;
		monthsPeriodsView = new MonthsPeriodsView();
		monthsPeriodsView.setMonthPeriodId(dto.getMonthPeriodId());
		monthsPeriodsView.setShortName(dto.getShortName());
		monthsPeriodsView.setDescription(dto.getDescription());
		monthsPeriodsView.setMonth(dto.getMonth());
		monthsPeriodsView.setYear(dto.getYear());
		monthsPeriodsView.setListDescription(dto.getListDescription());
		monthsPeriodsView.setLabel(new StringBuffer(dto.getShortName()).append(StringUtils.SPACE_CHAR).append(dto.getYear()).toString());
		return monthsPeriodsView;		
	}
	
	
	/**
	 * Months Periods Converter List View to DTO 
	 * @param plantDTOs
	 * @return
	 */
	public List convertViews(List monthsPeriodsDTO){
		List monthsPeriodsDTOs = null;
		monthsPeriodsDTOs = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(monthsPeriodsDTO)){
			Iterator iterator = monthsPeriodsDTO.iterator();
			MonthsPeriodsView e = null;
			while(iterator.hasNext()){
				e = (MonthsPeriodsView) iterator.next();
				monthsPeriodsDTOs.add(converterMonthsPeriodsViewToDTO(e));
			}
		}
		return monthsPeriodsDTOs;
	}
	
	
	
	/**
	 * Months Periods  Converter List DTO to View
	 * @param plantDTOs
	 * @return
	 */
	public List convertDTOs(List monthsPeriodsView){
		List monthsPeriodsViews = null;
		monthsPeriodsViews = new ArrayList(0);
		
		if(!CollectionUtils.isEmpty(monthsPeriodsView)){
			Iterator iterator = monthsPeriodsView.iterator();
			MonthsPeriodsDTO e = null;
			while(iterator.hasNext()){
				e = (MonthsPeriodsDTO) iterator.next();
				monthsPeriodsViews.add(converterMonthsPeriodsDtoToView(e));
			}
		}
		return monthsPeriodsViews;
	}
	
	
}
